package com.ewzj.bigdata.mvp.model

import android.app.Application
import com.ewzj.bigdata.app.config.netmodel.CommonCache
import com.ewzj.bigdata.app.config.netmodel.CommonService
import com.ewzj.bigdata.app.utils.Apputils
import com.ewzj.bigdata.mvp.contract.RealNewsFragmentContract
import com.ewzj.bigdata.mvp.model.reqbean.Reqpagebean
import com.ewzj.bigdata.mvp.model.rspbean.BaseData
import com.ewzj.bigdata.mvp.model.rspbean.InfosData
import com.google.gson.Gson
import com.jess.arms.integration.IRepositoryManager
import com.jess.arms.mvp.BaseModel
import com.jess.arms.utils.DeviceUtils
import io.reactivex.Observable
import io.rx_cache2.DynamicKey
import io.rx_cache2.EvictDynamicKey
import javax.inject.Inject

/**
 * author:zhangjing
 * 作用:
 * return:
 */
class RealNewsFragmentModel @Inject constructor(val mGson :Gson,val application: Application,repository: IRepositoryManager):BaseModel(repository),RealNewsFragmentContract.Model{
    val service=repository.obtainRetrofitService(CommonService::class.java)
    val cache=repository.obtainCacheService(CommonCache::class.java)
    override fun getInfos(page: Reqpagebean): Observable<InfosData> {
        return cache.infoList(service.infoList(Apputils.Utils.json2Requestbody(mGson.toJson(page))).map { t: BaseData<InfosData> -> t.data }, DynamicKey(1), EvictDynamicKey(DeviceUtils.hasInternet(application)))
    }

}